import BaseSprite from "../../../Script/Base/BaseSprite";
import { EResType } from "../../../Script/Common/Enum";
import { LoadUtil } from "../../../Script/Util/LoadUtil";
import ChatUI, { IShowDatas } from "./ChatUI";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ItemName extends BaseSprite {

    @property({ type: cc.Node, tooltip: "小红点提示" })
    private redPoint: cc.Node = null;

    @property({ type: cc.Sprite, tooltip: "icon" })
    private icon: cc.Sprite = null;

    @property({ type: cc.Label, tooltip: "名字" })
    private labName: cc.Label = null;

    @property({ type: cc.Label, tooltip: "最后一句聊天内容" })
    private labChat: cc.Label = null;

    private data: IShowDatas = null;

    public setData(data: IShowDatas) {
        this.data = data;
        this.labName.string = ChatUI.instance.getNameString(data.names);
        this.labChat.string = ChatUI.instance.getChatString(data.datas);

        this.redPoint.active = data.isPoint;

        LoadUtil.instance.setSpriteFrame(this.icon, EResType.BubbleIcon, data.names[0], 100, 100);
    }

    private onselfBtnClicked(event: cc.Event.EventTouch, data: cc.Event.EventCustom) {
        ChatUI.instance.clickID = this.data.chatId;
        ChatUI.instance.showChatPage(this.data, true);
    }
}